rm tabla_results
List_Z_tex=("Z_{A}" "Z_{V}" "Z_{P}^{RGI}(a^{-1})" "Z_{S}^{RGI}(a^{-1})" "Z_{T}^{RGI}(a^{-1})" "Z_{q}^{RGI}(a^{-1})")
List_Z=("A" "V" "P" "S" "T" "q")
NZ=${#List_Z[*]}
NZm1=$(echo "$NZ - 1 " | bc -l )

List_Oa2=("uncor" "Oa2g2" "Oa2g2b")
List_beta=("1.90" "1.95" "2.10")
List_beta100=(190 195 210)
Nbeta=${#List_beta100[*]}
Nbetam1=$(echo "$Nbeta - 1 " | bc -l )
list_demo=("000+" "++++" "++++")

for iZ in `seq 0 ${NZm1}`
do

Z_tex=${List_Z_tex[$iZ]}
Z=${List_Z[$iZ]}

echo $Z_tex
echo $Z

echo "\\begin{tabular}{|cccc|}" >> tabla_results
echo "\\hline " >> tabla_results
echo "\\multicolumn{4}{|c|}{\$${Z_tex}\$}\\tabularnewline">> tabla_results
echo "\\hline ">> tabla_results
echo " & ${List_beta[0]} & ${List_beta[1]} & ${List_beta[2]} \\tabularnewline">> tabla_results
echo "\\hline ">> tabla_results

for Oa2 in ${List_Oa2[*]}
do

echo "\\multicolumn{4}{|c|}{${Oa2}}\\tabularnewline" >> tabla_results
echo "\\hline ">> tabla_results

for method in "M1" "M2" 
do
echo -n $method >>tabla_results
for ibeta in `seq 0 $Nbetam1`
do
	beta100=${List_beta100[$ibeta]}
	#echo "$beta100 ${list_demo[$ibeta]}"
	if [ $beta100 -eq 195 ] ; then output_dir="OUTPUT-APE" ; else output_dir="OUTPUT"; fi
        if [ $beta100 -eq 195 ]
        then
                if [ $Z = "A" ]
		then
			 Z="V"  
                else 
			if [ $Z = "V" ] 
			then
				 Z="A"
			 fi
		fi
        fi

	tail -1 ~/workdir/lattice/RENORMALIZATION/DATA/$output_dir/TwistedMassNf4/b$beta100/Z2F/a/${list_demo[$ibeta]}/QAV/p2FIT/$method/Z${Z}_${Oa2}_RIp_ainv.dat >__tmp__
	Z=${List_Z[$iZ]}
          value=$(awk '{ print $1 }' __tmp__)
          jack=$(awk '{ print $2 }' __tmp__)
          sed "s/__VALUE__/$value/g;s/__JACK__/$jack/g" input.prec_nosist_template > input.prec
          ./writewithprecision_nosist > output.prec
          RC=$(sed -n '1p' output.prec)
          eRC=$(sed -n '2p' output.prec)
          rm input.prec
          rm output.prec
          echo -n "& $RC($eRC) " >>tabla_results
done
echo "\\tabularnewline" >>tabla_results
done

echo -n "slope" >>tabla_results

for ibeta in `seq 0 $Nbetam1`
do
        beta100=${List_beta100[$ibeta]}
#        echo "$beta100 ${list_demo[$ibeta]}"
        if [ $beta100 -eq 195 ] ; then output_dir="OUTPUT-APE" ; else output_dir="OUTPUT"; fi
        if [ $beta100 -eq 195 ]
        then
                if [ $Z = "A" ]
                then
                         Z="V"
                else
                        if [ $Z = "V" ]
                        then
                                 Z="A"
                         fi
                fi
        fi

        tail -1 ~/workdir/lattice/RENORMALIZATION/DATA/$output_dir/TwistedMassNf4/b$beta100/Z2F/a/${list_demo[$ibeta]}/QAV/p2FIT/M1/slope_Z${Z}_${Oa2}_RIp_ainv.dat >__tmp__
	Z=${List_Z[$iZ]}
          value=$(awk '{ print $1 }' __tmp__)
          jack=$(awk '{ print $2 }' __tmp__)
          sed "s/__VALUE__/$value/g;s/__JACK__/$jack/g" input.prec_nosist_template > input.prec
          ./writewithprecision_nosist > output.prec
          RC=$(sed -n '1p' output.prec)
          eRC=$(sed -n '2p' output.prec)
          rm input.prec
          rm output.prec
          echo -n "& $RC($eRC) " >>tabla_results
done
echo "\\tabularnewline" >>tabla_results


echo "\\hline ">> tabla_results


done
echo "\\end{tabular}">> tabla_results
echo "\\vspace{1cm}" >> tabla_results

echo "" >> tabla_results
done



